package com.kucai.yifaqapp.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.global.Info;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.Pay_SingleCzBean;
import com.kucai.yifaqapp.model.network.entity.res.z_alipay_ty;
import com.kucai.yifaqapp.util.SYSOUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;


/**
 * Created by admin on 2018/12/4.
 */

public class Z_alipayctivityThree extends BaseActivitySimple {
    TextView cr001;
    TextView cr002;
    TextView cr003;
    TextView cr004;
    TextView cr005;
    TextView cr006;
    TextView cr007;
    TextView cr008;
    Button cr009;
    RelativeLayout back;
    LinearLayout skinbg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.z_alipay3);
        back = findViewById(R.id.back);
        skinbg=findViewById(R.id.skinbg);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initview();
    }

    @Override
    protected int setContentView() {
        return R.layout.z_alipay3;
    }

    @Override
    protected void ChangeSkin() {
        switch (SkinId) {
            case 17771:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
                break;
            case 17772:
                skinbg.setBackgroundResource(R.mipmap.skin_bg2);
                break;
            case 17773:
                skinbg.setBackgroundResource(R.mipmap.skin_bg3);
                break;
            default:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
        }
    }

    private void initview() {
        cr001 = findViewById(R.id.cr001);
        cr002 = findViewById(R.id.cr002);
        cr003 = findViewById(R.id.cr003);
        cr004 = findViewById(R.id.cr004);
        cr005 = findViewById(R.id.cr005);
        cr006 = findViewById(R.id.cr006);
        cr007 = findViewById(R.id.cr007);
        cr008 = findViewById(R.id.cr008);
        cr009 = findViewById(R.id.cr009);
        cr001.setText("存入金额：" + z_alipay_ty.rechMoney);
        cr002.setText("账号信息：" + z_alipay_ty.realName);
        cr003.setText("存款时间：" + z_alipay_ty.rechTime);
        cr004.setText("存款方式：" + z_alipay_ty.yinghang);
        cr005.setText("开户银行：" + z_alipay_ty.yinghang);
        cr006.setText("开户网点：" + z_alipay_ty.wangdian);
        cr007.setText("姓名：" + z_alipay_ty.xingming);
        cr008.setText("账号：" + z_alipay_ty.kahao);
        cr009.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                save();
            }
        });
    }

    private void save() {
        //获取当前服务器时间
        HttpJsonUtils.getHttpApiInstance()
                .getSingleCz( HttpAdress.getuseAdress() + "api/m/bank/save",z_alipay_ty.cfgId, z_alipay_ty.rechMoney, z_alipay_ty.realName, z_alipay_ty.rechTime, Info.user.token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Pay_SingleCzBean>(this) {
                    @Override
                    protected void onCustomNext(Pay_SingleCzBean resBanner) {
                        try {
                            if (resBanner.getCode() == 0) {
                                Toast.makeText(Z_alipayctivityThree.this, "提交成功", Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(Z_alipayctivityThree.this, resBanner.getMsg(), Toast.LENGTH_LONG).show();
                            }
                        } catch (Exception e) {
                            Toast.makeText(Z_alipayctivityThree.this, "异常错误，请重新操作", Toast.LENGTH_LONG).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                        SYSOUtils.sOut(e.toString());
                    }
                });
    }

    private void initData() {

    }
}
